package org.company.management.utilities;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;

import com.richclientgui.toolbox.validation.LoggingErrorMessageHandler;
import com.richclientgui.toolbox.validation.ValidatingField;
import com.richclientgui.toolbox.validation.ValidationToolkit;
import com.richclientgui.toolbox.validation.string.StringValidationToolkit;
import com.richclientgui.toolbox.validation.validator.IFieldValidator;

/**
 * @author J
 *
 */
public class CustomValidatedText implements IValidator
{

	private ValidatingField<String> _customText;
	
	public CustomValidatedText (Composite parent, IFieldValidator<String> fieldValidator )
	{
		ValidationToolkit<String> _stringValToolkit = new StringValidationToolkit(SWT.TOP | SWT.LEFT, 1, true);
		
		_stringValToolkit.setDefaultErrorMessageHandler(new LoggingErrorMessageHandler());

		_customText = _stringValToolkit.createTextField(parent, fieldValidator, true, "");
	}
	
	@Override
	public String getText( )
	{
		return _customText.getContents().toString();
		
	}

	@Override
	public void setBounds( int x, int y, int width, int height )
	{
		_customText.getControl().setBounds(x, y, width, height);
	}

	@Override
	public void setText( String value )
	{
		_customText.setContents(value);
		
	}

	@Override
	public boolean isValid( )
	{
		return _customText.isValid();
	}
	
}
